package com.jy.rhin.facade.infra.controller.notification;

import com.jy.framework.base.entity.Page;
import com.jy.framework.base.entity.Result;
import com.jy.rhin.application.infra.NotificationApplicationService;
import com.jy.rhin.domain.notification.topic.entity.TopicDO;
import com.jy.rhin.infra.repo.notfication.topic.query.TopicQueryHandler;
import com.jy.rhin.sdk.dto.notification.req.IdDto;
import com.jy.rhin.sdk.dto.notification.req.TopicExpDto;
import com.jy.rhin.sdk.dto.notification.req.TopicQueryPageReqDto;
import com.jy.rhin.sdk.dto.notification.resp.*;
import com.jy.rhin.sdk.feign.client.TopicFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author WeiQ
 * @date 2022/6/28 16:26
 */
@RestController
@RequestMapping("/infra/notification/topic")
@Api(tags = "事件总线api", value = "主题记录api")
@Slf4j
public class TopicController implements TopicFeign {

    @Resource
    NotificationApplicationService notificationApplicationService;

    @Resource
    TopicQueryHandler topicQueryHandler;

    @ApiOperation(value = "主题记录api-保存主题信息", notes = "仅做测试用，暂不对外开放主题维护接口", hidden = true)
    @PostMapping("/save")
    public Result<Long> save(@RequestBody TopicDO topic) {
        Long topicId = notificationApplicationService.create(topic);
        return Result.success(topicId);
    }

    @Override
    @ApiOperation(value = "主题记录api-分页查询主题列表")
    @GetMapping("/queryPage")
    public Result<Page<TopicInfoDto>> queryPage(TopicQueryPageReqDto dto) {
        return Result.success(topicQueryHandler.queryPage(dto));
    }

    @Override
    @ApiOperation(value = "主题记录api-查询主题详情")
    @GetMapping("/queryTopicDetail")
    public Result<TopicDetailDto> queryTopicDetail(IdDto dto) {
        return Result.success(topicQueryHandler.queryTopicDetail(dto.getId()));
    }

    @Override
    @ApiOperation(value = "主题记录api-查询主题列表")
    @GetMapping("/queryTopicList")
    public Result<List<TopicShortDto>> queryTopicList(){
        return Result.success(topicQueryHandler.queryTopicList());
    }

    @Override
    @ApiOperation(value = "主题记录api-根据主题表达式获取预存函数列表")
    @GetMapping("/queryTopicQueryAndTopicFilterList")
    public Result<List<TopicQueryDto>> queryTopicQueryAndTopicFilterList(TopicExpDto dto){
        return Result.success(topicQueryHandler.queryTopicQueryAndTopicFilterList(dto));
    }

    @Override
    @ApiOperation(value = "主题记录api-查询主题消息属性字段")
    @GetMapping("/queryTopicProperties")
    public Result<List<TopicPropertiesDto>> queryTopicProperties(TopicExpDto dto) {
        return Result.success(topicQueryHandler.queryTopicProperties(dto.getTopicExp()));
    }

    @Override
    @ApiOperation(value = "主题记录api-统计主题数量(业务服务)")
    @GetMapping("/countTopic")
    public Result<Integer> countTopic() {
        return Result.success(topicQueryHandler.countTopic());
    }

    @Override
    @ApiOperation(value = "主题记录api-查询事件主题列表(业务服务)")
    @GetMapping("/queryEventTopicList")
    public Result<List<EventTopicListDto>> queryEventTopicList() {
        return Result.success(topicQueryHandler.queryEventTopicList(10));
    }


}
